package com.itgacl.mqtt.client;

import com.itgacl.mqtt.client.annotation.EnableMqttClient;
import com.itgacl.mqtt.client.config.MqttClientConfig;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.paho.client.mqttv3.IMqttMessageListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Slf4j
@Configuration
@ConditionalOnBean(annotation = EnableMqttClient.class)
@EnableConfigurationProperties(MqttClientConfig.class)
public class MqttClientAutoConfiguration {

    @Autowired
    private MqttClientConfig mqttClientConfig;

    @Autowired
    private IMqttMessageListener mqttMessageListener;

    @Bean
    public MqttClientService mqttClientService(){
        log.debug("MqttClientAutoConfiguration init mqttClientService");
        return new MqttClientService(mqttClientConfig,mqttMessageListener);
    }
}
